package com.kadron.dao;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.intercept.BypassInterceptors;

import com.kadron.entity.NewsLetter;

@AutoCreate
@BypassInterceptors
@Name("newsletterDAO")
public class KNewsletterDAO extends KDAO<NewsLetter> {

	@SuppressWarnings("unchecked")
	public List<NewsLetter> getNewsletters(Date date) {
		EntityManager em = getEntityManager();
		return em.createQuery("SELECT DISTINCT e FROM NewsLetter e WHERE e.processed = FALSE AND e.start < :moment AND e.active = TRUE")
				.setParameter("moment", date)
				.getResultList();
	}
	
}
